<template>
  <div id="app">
    <button @click="getCity">查询当前所在城市信息</button>
    {{ city }}
  </div>
</template>

<script>
export default {
  data() {
    return {
      city: "",
    };
  },
  methods: {
    getCity() {
      AMap.plugin("AMap.CitySearch", function () {
        var citySearch = new AMap.CitySearch();
        citySearch.getLocalCity(function (status, result) {
          if (status === "complete" && result.info === "OK") {
            // 查询成功，result即为当前所在城市信息
            window.city = result.city;
          }
        });
      });
    },
  },
};
</script>

<style scoped></style>
